import collections
from random import choice

# namedtuple 用以构建只有少数属性但是没有方法的对象
Card = collections.namedtuple('Card', ['rand', 'suit'])

class FrencDeck:
    ranks = [str(n) for n in range(2, 11)] + list('JQKA')
    suits = '黑桃 方块 梅花 红桃'.split()

    def __init__(self) -> None:
        self._cards = [Card(rank, suit) for suit in self.suits
                                        for rank in self.ranks]

    def __len__(self):
        return len(self._cards)

    def __getitem__(self, position):
        return self._cards[position]


deck = FrencDeck()
print(len(deck))

# random.choice，从一个序列中随机取一个元素
random_deck = choice(deck)
print(random_deck)

print(deck[:3])
print(deck[12:13])
